<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.13.1"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>mi-malloc: Aligned Allocation</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<script type="text/javascript" src="clipboard.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="cookie.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
  $(function() { init_search(); });
/* @license-end */
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="mimalloc-doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectlogo"><img alt="Logo" src="mimalloc-logo.svg"/></td>
  <td id="projectalign">
   <div id="projectname">mi-malloc<span id="projectnumber">&#160;1.8/2.1</span>
   </div>
  </td>
    <td>        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <span id="MSearchSelect"                onmouseover="return searchBox.OnSearchSelectShow()"                onmouseout="return searchBox.OnSearchSelectHide()">&#160;</span>
          <input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.svg" alt=""/></a>
          </span>
        </div>
</td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.13.1 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search/",'.html');
/* @license-end */
</script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() { codefold.init(0); });
/* @license-end */
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function(){initNavTree('group__aligned.html',''); initResizable(true); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>

<div class="header">
  <div class="summary">
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle"><div class="title">Aligned Allocation</div></div>
</div><!--header-->
<div class="contents">

<p>Allocating aligned memory blocks.  
<a href="#details">More...</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:ga69578ff1a98ca16e1dcd02c0995cd65c" id="r_ga69578ff1a98ca16e1dcd02c0995cd65c"><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#ga69578ff1a98ca16e1dcd02c0995cd65c">mi_malloc_aligned</a> (size_t size, size_t alignment)</td></tr>
<tr class="memdesc:ga69578ff1a98ca16e1dcd02c0995cd65c"><td class="mdescLeft">&#160;</td><td class="mdescRight">Allocate <em class="arg">size</em> bytes aligned by <em class="arg">alignment</em>.  <br /></td></tr>
<tr class="separator:ga69578ff1a98ca16e1dcd02c0995cd65c"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gaac7d0beb782f9b9ac31f47492b130f82" id="r_gaac7d0beb782f9b9ac31f47492b130f82"><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#gaac7d0beb782f9b9ac31f47492b130f82">mi_zalloc_aligned</a> (size_t size, size_t alignment)</td></tr>
<tr class="separator:gaac7d0beb782f9b9ac31f47492b130f82"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga424ef386fb1f9f8e0a86ab53f16eaaf1" id="r_ga424ef386fb1f9f8e0a86ab53f16eaaf1"><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#ga424ef386fb1f9f8e0a86ab53f16eaaf1">mi_calloc_aligned</a> (size_t count, size_t size, size_t alignment)</td></tr>
<tr class="separator:ga424ef386fb1f9f8e0a86ab53f16eaaf1"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga5d7a46d054b4d7abe9d8d2474add2edf" id="r_ga5d7a46d054b4d7abe9d8d2474add2edf"><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#ga5d7a46d054b4d7abe9d8d2474add2edf">mi_realloc_aligned</a> (void *p, size_t newsize, size_t alignment)</td></tr>
<tr class="separator:ga5d7a46d054b4d7abe9d8d2474add2edf"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga2022f71b95a7cd6cce1b6e07752ae8ca" id="r_ga2022f71b95a7cd6cce1b6e07752ae8ca"><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#ga2022f71b95a7cd6cce1b6e07752ae8ca">mi_malloc_aligned_at</a> (size_t size, size_t alignment, size_t offset)</td></tr>
<tr class="memdesc:ga2022f71b95a7cd6cce1b6e07752ae8ca"><td class="mdescLeft">&#160;</td><td class="mdescRight">Allocate <em class="arg">size</em> bytes aligned by <em class="arg">alignment</em> at a specified <em class="arg">offset</em>.  <br /></td></tr>
<tr class="separator:ga2022f71b95a7cd6cce1b6e07752ae8ca"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga7c1778805ce50ebbf02ccbd5e39d5dba" id="r_ga7c1778805ce50ebbf02ccbd5e39d5dba"><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#ga7c1778805ce50ebbf02ccbd5e39d5dba">mi_zalloc_aligned_at</a> (size_t size, size_t alignment, size_t offset)</td></tr>
<tr class="separator:ga7c1778805ce50ebbf02ccbd5e39d5dba"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga977f96bd2c5c141bcd70e6685c90d6c3" id="r_ga977f96bd2c5c141bcd70e6685c90d6c3"><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#ga977f96bd2c5c141bcd70e6685c90d6c3">mi_calloc_aligned_at</a> (size_t count, size_t size, size_t alignment, size_t offset)</td></tr>
<tr class="separator:ga977f96bd2c5c141bcd70e6685c90d6c3"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gad06dcf2bb8faadb2c8ea61ee5d24bbf6" id="r_gad06dcf2bb8faadb2c8ea61ee5d24bbf6"><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#gad06dcf2bb8faadb2c8ea61ee5d24bbf6">mi_realloc_aligned_at</a> (void *p, size_t newsize, size_t alignment, size_t offset)</td></tr>
<tr class="separator:gad06dcf2bb8faadb2c8ea61ee5d24bbf6"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<p>Allocating aligned memory blocks. </p>
<p>Note that <code>alignment</code> always follows <code>size</code> for consistency with the unaligned allocation API, but unfortunately this differs from <code>posix_memalign</code> and <code>aligned_alloc</code> in the C library. </p>
<h2 class="groupheader">Function Documentation</h2>
<a id="ga424ef386fb1f9f8e0a86ab53f16eaaf1" name="ga424ef386fb1f9f8e0a86ab53f16eaaf1"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga424ef386fb1f9f8e0a86ab53f16eaaf1">&#9670;&#160;</a></span>mi_calloc_aligned()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void * mi_calloc_aligned </td>
          <td>(</td>
          <td class="paramtype">size_t</td>          <td class="paramname"><span class="paramname"><em>count</em></span>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t</td>          <td class="paramname"><span class="paramname"><em>size</em></span>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t</td>          <td class="paramname"><span class="paramname"><em>alignment</em></span>&#160;)</td>
        </tr>
      </table>
</div><div class="memdoc">

</div>
</div>
<a id="ga977f96bd2c5c141bcd70e6685c90d6c3" name="ga977f96bd2c5c141bcd70e6685c90d6c3"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga977f96bd2c5c141bcd70e6685c90d6c3">&#9670;&#160;</a></span>mi_calloc_aligned_at()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void * mi_calloc_aligned_at </td>
          <td>(</td>
          <td class="paramtype">size_t</td>          <td class="paramname"><span class="paramname"><em>count</em></span>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t</td>          <td class="paramname"><span class="paramname"><em>size</em></span>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t</td>          <td class="paramname"><span class="paramname"><em>alignment</em></span>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t</td>          <td class="paramname"><span class="paramname"><em>offset</em></span>&#160;)</td>
        </tr>
      </table>
</div><div class="memdoc">

</div>
</div>
<a id="ga69578ff1a98ca16e1dcd02c0995cd65c" name="ga69578ff1a98ca16e1dcd02c0995cd65c"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga69578ff1a98ca16e1dcd02c0995cd65c">&#9670;&#160;</a></span>mi_malloc_aligned()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void * mi_malloc_aligned </td>
          <td>(</td>
          <td class="paramtype">size_t</td>          <td class="paramname"><span class="paramname"><em>size</em></span>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t</td>          <td class="paramname"><span class="paramname"><em>alignment</em></span>&#160;)</td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Allocate <em class="arg">size</em> bytes aligned by <em class="arg">alignment</em>. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">size</td><td>number of bytes to allocate. </td></tr>
    <tr><td class="paramname">alignment</td><td>the minimal alignment of the allocated memory. </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>pointer to the allocated memory or <em class="arg">NULL</em> if out of memory, or if the alignment is not a power of 2 (including 0). The <em class="arg">size</em> is unrestricted (and does not have to be an integral multiple of the <em class="arg">alignment</em>). The returned pointer is aligned by <em class="arg">alignment</em>, i.e. <code>(uintptr_t)p % alignment == 0</code>. Returns a unique pointer if called with <em class="arg">size</em> 0.</dd></dl>
<p>Note that <code>alignment</code> always follows <code>size</code> for consistency with the unaligned allocation API, but unfortunately this differs from <code>posix_memalign</code> and <code>aligned_alloc</code> in the C library.</p>
<dl class="section see"><dt>See also</dt><dd><a href="https://en.cppreference.com/w/c/memory/aligned_alloc">aligned_alloc</a> (in the standard C11 library, with switched arguments!) </dd>
<dd>
<a href="https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/aligned-malloc?view=vs-2017">_aligned_malloc</a> (on Windows) </dd>
<dd>
<a href="http://man.openbsd.org/reallocarray">aligned_alloc</a> (on BSD, with switched arguments!) </dd>
<dd>
<a href="https://linux.die.net/man/3/posix_memalign">posix_memalign</a> (on Posix, with switched arguments!) </dd>
<dd>
<a href="https://linux.die.net/man/3/posix_memalign">memalign</a> (on Linux, with switched arguments!) </dd></dl>

</div>
</div>
<a id="ga2022f71b95a7cd6cce1b6e07752ae8ca" name="ga2022f71b95a7cd6cce1b6e07752ae8ca"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga2022f71b95a7cd6cce1b6e07752ae8ca">&#9670;&#160;</a></span>mi_malloc_aligned_at()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void * mi_malloc_aligned_at </td>
          <td>(</td>
          <td class="paramtype">size_t</td>          <td class="paramname"><span class="paramname"><em>size</em></span>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t</td>          <td class="paramname"><span class="paramname"><em>alignment</em></span>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t</td>          <td class="paramname"><span class="paramname"><em>offset</em></span>&#160;)</td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Allocate <em class="arg">size</em> bytes aligned by <em class="arg">alignment</em> at a specified <em class="arg">offset</em>. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">size</td><td>number of bytes to allocate. </td></tr>
    <tr><td class="paramname">alignment</td><td>the minimal alignment of the allocated memory at <em class="arg">offset</em>. </td></tr>
    <tr><td class="paramname">offset</td><td>the offset that should be aligned. </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>pointer to the allocated memory or <em class="arg">NULL</em> if out of memory, or if the alignment is not a power of 2 (including 0). The <em class="arg">size</em> is unrestricted (and does not have to be an integral multiple of the <em class="arg">alignment</em>). The returned pointer is aligned by <em class="arg">alignment</em>, i.e. <code>(uintptr_t)p % alignment == 0</code>. Returns a unique pointer if called with <em class="arg">size</em> 0.</dd></dl>
<dl class="section see"><dt>See also</dt><dd><a href="https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/aligned-offset-malloc?view=vs-2017">_aligned_offset_malloc</a> (on Windows) </dd></dl>

</div>
</div>
<a id="ga5d7a46d054b4d7abe9d8d2474add2edf" name="ga5d7a46d054b4d7abe9d8d2474add2edf"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga5d7a46d054b4d7abe9d8d2474add2edf">&#9670;&#160;</a></span>mi_realloc_aligned()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void * mi_realloc_aligned </td>
          <td>(</td>
          <td class="paramtype">void *</td>          <td class="paramname"><span class="paramname"><em>p</em></span>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t</td>          <td class="paramname"><span class="paramname"><em>newsize</em></span>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t</td>          <td class="paramname"><span class="paramname"><em>alignment</em></span>&#160;)</td>
        </tr>
      </table>
</div><div class="memdoc">

</div>
</div>
<a id="gad06dcf2bb8faadb2c8ea61ee5d24bbf6" name="gad06dcf2bb8faadb2c8ea61ee5d24bbf6"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gad06dcf2bb8faadb2c8ea61ee5d24bbf6">&#9670;&#160;</a></span>mi_realloc_aligned_at()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void * mi_realloc_aligned_at </td>
          <td>(</td>
          <td class="paramtype">void *</td>          <td class="paramname"><span class="paramname"><em>p</em></span>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t</td>          <td class="paramname"><span class="paramname"><em>newsize</em></span>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t</td>          <td class="paramname"><span class="paramname"><em>alignment</em></span>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t</td>          <td class="paramname"><span class="paramname"><em>offset</em></span>&#160;)</td>
        </tr>
      </table>
</div><div class="memdoc">

</div>
</div>
<a id="gaac7d0beb782f9b9ac31f47492b130f82" name="gaac7d0beb782f9b9ac31f47492b130f82"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gaac7d0beb782f9b9ac31f47492b130f82">&#9670;&#160;</a></span>mi_zalloc_aligned()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void * mi_zalloc_aligned </td>
          <td>(</td>
          <td class="paramtype">size_t</td>          <td class="paramname"><span class="paramname"><em>size</em></span>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t</td>          <td class="paramname"><span class="paramname"><em>alignment</em></span>&#160;)</td>
        </tr>
      </table>
</div><div class="memdoc">

</div>
</div>
<a id="ga7c1778805ce50ebbf02ccbd5e39d5dba" name="ga7c1778805ce50ebbf02ccbd5e39d5dba"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga7c1778805ce50ebbf02ccbd5e39d5dba">&#9670;&#160;</a></span>mi_zalloc_aligned_at()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void * mi_zalloc_aligned_at </td>
          <td>(</td>
          <td class="paramtype">size_t</td>          <td class="paramname"><span class="paramname"><em>size</em></span>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t</td>          <td class="paramname"><span class="paramname"><em>alignment</em></span>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t</td>          <td class="paramname"><span class="paramname"><em>offset</em></span>&#160;)</td>
        </tr>
      </table>
</div><div class="memdoc">

</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.13.1 </li>
  </ul>
</div>
</body>
</html>
